#include "Tileset.hpp"
#include "Texture.hpp"
#include "../math/Vector2.hpp"

namespace yep
{
Tileset::Tileset()
{
    tileWidth = tileHeight = 0;
    texture = NULL;
}

Tileset::Tileset( Texture &texture_, Uint8 tileWidth_, Uint8 tileHeight_ )
{
    tileWidth  = tileWidth_;
    tileHeight = tileHeight_;
    texture    = &texture_;
    evaluateSize();
}

Tileset::~Tileset()
{
}

void Tileset::draw( Canvas &dst, const Vector2 &position, int index )
{
    texture->draw( dst, position, Vector2( (double)(index % rowSize * tileWidth), (double)(index / rowSize * tileHeight) ), Vector2 (tileWidth, tileHeight) );
}

unsigned Tileset::getSize()
{
    return size;
}

void Tileset::evaluateSize()
{
    rowSize = texture->getWidth() / tileWidth;
    size    = rowSize * texture->getHeight() / tileHeight;
}

}
